package mtn.bowen.yan.server.dao;

import mtn.bowen.yan.server.model.PictureDishes;
import mtn.bowen.yan.server.model.VarietyDishes;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author <a href=mailto:yanbowen90@foxmail.com> bowen.yan </a>
 * @version 1.0
 * @description: 菜品名称种类大厨关系表
 * @date 2021-10-23 9:31 PM
 */
@Mapper
@Repository
public interface PictureOfDishesDao {

    String ID = "id";

    String TABLE_NAME = "picture_of_dishes";

    String ALL_FIELDS = "id,uuid,name,kind,chef,introduce";

    String UNIQUE_FIELDS = "`uuid`, `kind`, `chef`";

    String OTHER_FIELDS = "`name`, `introduce`";

    @Select("select " + ALL_FIELDS + " from " + TABLE_NAME)
    List<PictureDishes> selectAll();

    @Select("select " + ALL_FIELDS + " from " + TABLE_NAME + " where kind = #{kind} ")
    List<PictureDishes> selectByKind(@Param("kind") Integer kind);

    @Insert("INSERT INTO " + TABLE_NAME + " (" + UNIQUE_FIELDS + ", " + OTHER_FIELDS + ") VALUES (#{uuid}, #{kind}, #{chef}, #{name}, #{introduce})")
    @Options(useGeneratedKeys = true, keyColumn = ID)
    int insertPictureDishes(PictureDishes pictureDishes);

    @Delete({"delete from " + TABLE_NAME + " where uuid = #{uuid}"})
    int deleteByUUid(@Param("uuid") String uuid);

    @Select("select " + ALL_FIELDS + " from " + TABLE_NAME + " where uuid = #{uuid} ")
    PictureDishes selectByUUid(@Param("uuid") String uuid);
}
